<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>当前有效待租信息</title>
<link rel="styleSheet" href="../../css/bootstrap.min.css"> 
<style type="text/css">
	#myDiv{
		width:1000px;
		margin-left: 60px;
		margin-top: 90px;
	}
	#fenteDiv{
		width:1000px;
		margin-left: 60px;
		margin-top: 0px;
		text-align: center;
	}
	#noticeDiv{
		width:600px;
		margin-left: 160px;
		margin-top: 0px;
		text-align: center;
	}
	td{
		text-align: center;
	}
</style>
</head>
<body style="background-color: transparent;">
	<input type="hidden" id="ladyID" value="${sessionScope.myLandLady.ladyID }">
	<div	id="myDiv">
		<table id="infoTable" class="table table-striped table table-bordered">
			<tr>
				<td>编号</td>
				<td>出租车位</td>
				<td>开始时间</td>
				<td>结束时间</td>
				<td>点击详情</td>
			</tr>
		</table>
	</div>
	<div class="tcdPageCode" id="fenteDiv">
	<ul style="position:absolute;left:300px;top:360px;" class="pager">
			<li><a href="javascript:void(0)" id="firstPage">首页</a></li>
			<li><a href="javascript:void(0)" id="pageUp">前一页</a></li>
			<li><label id="currentPage"></label><label>/</label><label
				id="pageCount"></label></li>
			<li><a href="javascript:void(0)" id="pageDown">下一页</a></li>
			<li><a href="javascript:void(0)" id="lastPage">末页</a>跳转至<input style="width:50px;" id="pagess" name="page" type="text" size="2"  maxlength="2" value="1" onkeyup='this.value=this.value.replace(/\D/gi,"")'>页</li>
			<li><a href="javascript:void(0)" id="forPage">跳转</a></li>
	</ul>		
    </div>
    <div id="noticeDiv">
    <label id="notice" style="color:red;"></label>
    </div>
</body>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	$(function(){
		init();
	})
	function init(){
		findAllRentInfo(1);
	}
	function findAllRentInfo(curPage){
		var tr="";
		var ladyID = $("#ladyID").val();
		$.ajax({
			url:"showAllWaitRent.do",
			type:"post",
			async:true,
			data:{"curPage":curPage,"ladyID":ladyID},
			success:function(msg){
				for (var i = 0; i < msg.list.length; i++) {
					var startTime = new Date(msg.list[i].startTime);
					var endTime = new Date(msg.list[i].endTime);
					var index = new Number(i+1);
					tr+="<tr><td>"+index+"</td><td>"
								+msg.list[i].personalcarport.carportAddress+msg.list[i].personalcarport.carNO+"</td><td>"
								+startTime.getFullYear()+"年"+(startTime.getUTCMonth()+1)+"月"+(startTime.getUTCDate()+1)+"日"+startTime.getHours()+"时"+"</td><td>"
								+endTime.getFullYear()+"年"+(endTime.getUTCMonth()+1)+"月"+(endTime.getUTCDate()+1)+"日"+endTime.getHours()+"时"+"</td><td><button id='"+msg.list[i].rentInfoID+"' class='info btn btn-primary'>详情</button></td></tr>"
					
				}
				if(msg.list.length==0){
					$("#currentPage").html("0");
					$("#pageCount").html("0");
				}else{
					$("#currentPage").html(msg.curPage);
					$("#pageCount").html(msg.countPage);
				}
				$("#infoTable").append(tr);
			}
		})
	}
	$(".pager a").click	(function(){
		var curPage=$("#currentPage").html();
		var countPage=$("#pageCount").html();
		var pageFtn=$(this).html();
		
		if(pageFtn=="首页"){
			curPage=1;
		}
		if(pageFtn=="前一页"){
			
			curPage=parseInt(curPage)-1;
			if(curPage<1){
				curPage=1;
			}
		}
		if(pageFtn=="下一页"){
			
			curPage=parseInt(curPage)+1;
			if(curPage>countPage){
				curPage=countPage;
			}
		}
		if(pageFtn=="末页"){
			
			curPage=countPage;
		}
		if(pageFtn=="跳转"){
			
			var pagger=$("#pagess").val();
			if(pagger>countPage){
				curPage=countPage;
				$("#pagess").val(countPage);
			}else if(pagger<1){
				curPage=1;
				$("#pagess").val("1");
			}else if(pagger==""){
				curPage=1;
				$("#pagess").val("1");
			}else{
				curPage=pagger;
			}
		}
		$("#infoTable tr:gt(0)").remove();
		$("#currentPage").html(curPage);
		
		findAllRentInfo(curPage);
			
		});
	$(".info").live("click",function(){
		var id = $(this).attr("id");
		$.ajax({
			url:"checkHasPurpose.do",
			type:"post",
			async:true,
			data:{"id":id},
			success:function(msg){
				if(msg==0){
					$("#notice").html("这个车位暂时没有租客想租！");
					
				}else{
					window.location.href="purpose.jsp?id="+id;
				}
			}
			
		})
		$(this).blur(function(){
						$("#notice").html("");
					})
		
	})
	
</script>
</html>